package main

import (
	"fmt"
	"iter"
)

// 通过yiled函数将想要的输出的元素输出
func Backward[E any](s []E) iter.Seq2[int, E] {
	return func(yield func(int, E) bool) {
		for i := 0; i < len(s); i++ {
			if !yield(i, s[i]) {
				return
			}
		}
	}
}

func main() {
	sl := []string{"脑子", "进", "煎鱼", "了"}
	for i, s := range Backward(sl) {
		fmt.Printf("%d: %s\n", i, s)
	}

}
